#include <iostream>
#define LINKEDLIST struct LinkedList

using namespace std;
struct LinkedList {
	int data;
	LinkedList* next;
};

struct LinkedList* reverseLinkedList(LINKEDLIST* head)
{
	if (NULL == head) return head;
	if (NULL == head->next)return head;
	struct LinkedList* preNode = head;
	struct LinkedList* currentNode = head->next;	
	struct LinkedList* nextNode = currentNode->next;
	preNode->next = NULL;
	while (currentNode->next !=NULL) {
		nextNode = currentNode->next;
		currentNode->next = preNode;
		preNode = currentNode;
		currentNode = nextNode;
	}
	currentNode->next = preNode;
	return currentNode;
}

int main(int argc, char* agrv[])
{
	struct LinkedList tmp1, tmp2,tmp3, tmp4, tmp5;
    struct LinkedList* head;
	tmp1.data = 1;
	tmp1.next = &tmp2;
	tmp2.data = 2;
	tmp2.next = &tmp3;
	tmp3.data = 3;
	tmp3.next = &tmp4;
	tmp4.data=4;
	tmp4.next = &tmp5;
	tmp5.data = 5;
	tmp5.next = NULL;
    head = &tmp1;
	head = reverseLinkedList(&tmp1);
	while (head != NULL){
        cout << head->data << endl;
		head = head->next;
	}
	
	return 0;
}

